package com.imooc.reader;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.imooc.reader.entity.Test;
import com.imooc.reader.mapper.TestMapper;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class) // 初始化ioc容器
@ContextConfiguration(locations = {"classpath:applicationContext.xml"}) //加载当前的配置文件
public class MybatisPlusTest {
    @Resource // 注入用例接口
    private TestMapper testMapper;

    @org.junit.Test // 测试表test和junit包名重名了，所以加上这个注解
    public void testInsert() {
        Test test = new Test();
        test.setContent("MyBatisPlus测试");
        testMapper.insert(test);
    }

    @org.junit.Test
    public void testUpdate() {
        Test test = testMapper.selectById(1);
        test.setContent("MyBatisPlus测试修改");
        testMapper.updateById(test);
    }

    @org.junit.Test
    public void testDelete() {
        testMapper.deleteById(1);
    }

    @org.junit.Test
    public void testSelect() {
        QueryWrapper<Test> queryWrapper = new QueryWrapper<Test>();
        queryWrapper.eq("id", 2);
        queryWrapper.gt("id", 3);
        List<Test> tests = testMapper.selectList(queryWrapper);
    }
}
